/**
 * Copyright (c) iwindplus Technologies Co., Ltd.2024-2030, All rights reserved.
 */

package com.iwindplus.boot.web.domain.property;

import java.time.Duration;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.util.List;

/**
 * OkHttpClient相关属性.
 *
 * @author zengdegui
 * @since 2018/10/10
 */
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@ConfigurationProperties(prefix = "okhttp.client")
public class OkHttpClientProperty {

    /**
     * 是否启用.
     */
    @Builder.Default
    private Boolean enabled = Boolean.TRUE;

    /**
     * 最大连接数.
     */
    @Builder.Default
    private Integer maxConnTotal = 20;

    /**
     * 连接保持时间。如果超过这个时间没有任务调度，则会被回收（单位：秒）.
     */
    @Builder.Default
    private Duration connectionKeepAlive = Duration.ofSeconds(900);

    /**
     * 连接超时时间（单位：秒）.
     */
    @Builder.Default
    private Duration connectTimeout = Duration.ofSeconds(5);

    /**
     * 读取超时时间（单位：秒）.
     */
    @Builder.Default
    private Duration readTimeout = Duration.ofSeconds(60);

    /**
     * 写入超时时间（单位：秒）.
     */
    @Builder.Default
    private Duration writeTimeout = Duration.ofSeconds(10);

    /**
     * 调用超时时间（单位：秒）.
     */
    @Builder.Default
    private Duration callTimeout = Duration.ofSeconds(20);

    /**
     * 是否开启重试.
     */
    @Builder.Default
    private Boolean enableRetry = true;

    /**
     * 是否允许重定向.
     */
    @Builder.Default
    private Boolean followRedirects = true;

    /**
     * 协议.
     */
    @Builder.Default
    private List<String> protocols = List.of("HTTP_2", "HTTP_1_1");

    /**
     * 是否开启代理.
     */
    @Builder.Default
    private Boolean proxyEnable = false;

    /**
     * 代理主机（可选）.
     */
    private String proxyHost;

    /**
     * 代理主机端口（可选）.
     */
    private Integer proxyPort;

    /**
     * 代理的鉴权账号（可选）.
     */
    private String proxyUsername;

    /**
     * 代理的鉴权密码（可选）.
     */
    private String proxyPassword;
}
